#
# @lc app=leetcode.cn id=496 lang=python
#
# [496] 下一个更大元素 I
#

# @lc code=start
class Solution(object):
    def nextGreaterElement(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        result = [-1] * len(nums1)
        stack = []
        for i in range(len(nums2)):
            while stack and nums2[i] > nums1[stack[-1]]:
                result[stack[-1]] = nums2[i]
                stack.pop()
            
            if nums2[i] in nums1:
                stack.append(nums1.index(nums2[i]))
        return result
        
# @lc code=end

